package com.zzyl.common.utils.huawei;

import com.huaweicloud.sdk.core.auth.AbstractCredentials;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.region.Region;
import com.huaweicloud.sdk.iotda.v5.IoTDAClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2025/9/16 15:48
 */
@Configuration
public class HuaweiIotClientConfig {
    @Autowired
    private HuaWeiIotConfigProperties huaweiIotConfigProperties;

    @Bean
    public IoTDAClient huaweiIotClient(){
        ICredential auth = new BasicCredentials()
                .withProjectId(huaweiIotConfigProperties.getProjectId())
                // 标准版/企业版需要使用衍生算法，基础版请删除配置"withDerivedPredicate";
                .withDerivedPredicate(AbstractCredentials.DEFAULT_DERIVED_PREDICATE) // Used in derivative ak/sk authentication scenarios
                .withAk(huaweiIotConfigProperties.getAk())
                .withSk(huaweiIotConfigProperties.getSk());

        return IoTDAClient.newBuilder()
                .withCredential(auth)
                // 标准版/企业版：需自行创建Region对象，基础版：请使用IoTDARegion的region对象，如"withRegion(IoTDARegion.CN_NORTH_4)"
                .withRegion(new Region(huaweiIotConfigProperties.getRegionId(), huaweiIotConfigProperties.getEndpoint()))
                .build();
    }
}
